<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS</title>
  <style>

  </style>
  <style>
    #avatar{
      width: 150px;
      height:150px;
      object-fit: cover;
    }
    .rotate {
      animation: rotate 10s linear infinite;
    }

    @keyframes rotate {
      0% {
        transform: rotate(0);
      }

      25% {
        transform: rotate(90deg);
      }

      50% {
        transform: rotate(180deg);
      }

      75% {
        transform: rotate(270deg);
      }

      100% {
        transform: rotate(360deg);
      }
    }
  </style>
</head>

<body>
  <div>
    <p>帅气的头像</p>
    <img id="avatar" onclick="doit()"  src="./img/20211122235442_87c8c.jpg" alt="">
  </div>
  <script>
    function doit () {
      document.querySelector('#avatar').classList.add('rotate')
    }
  </script>
</body>

</html>